package cn.itcast.controller;

import cn.itcast.domain.Courier;
import cn.itcast.domain.Standard;
import cn.itcast.service.CourierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class CourierController {
    @Autowired
    private CourierService courierService;

    @RequestMapping("/courier_pageQuery")
    @ResponseBody
    public Map pageQuery( int page, int rows ,Courier courier) {
        Page<Courier> pageResult =  courierService.pageQuery(page, rows ,courier);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("total", pageResult.getTotalElements());
        result.put("rows", pageResult.getContent());

        return result;
    }


    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    }

    @RequestMapping("/courier_save")
    public String courierSave(Courier courier) {

        courierService.save(courier);
        return "redirect:/pages/base/courier.html";


    }


    @RequestMapping("/courier_delBatch")
    //@ResponseBody
    public String courierSave(String ids) {

        courierService.updateDeltag(Integer.parseInt(ids));


        return "redirect:/pages/base/courier.html";


    }

/*

   @RequestMapping("/findByCourier")
    public List<Courier> findByCourier(Courier courier) {

        return courierService.findByCourierNumOrCompanyOrVehicleType(courier);
    }
*/


   @RequestMapping("/courier_name")
  // @ResponseBody
    public String courierName(String ids) {

        courierService.updateDeltag1(Integer.parseInt(ids));


        return "redirect:/pages/base/courier.html";


    }

}
